/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.ProfileCompletion.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

/**
 *
 * @author Yogesh
 */
public class ProfileCompletion_Controller extends org.apache.struts.action.Action {
    
    /* forward name="success" path="" */
    private static final String SUCCESS = "ProfileCompletion";
    
    /**
     * This is the action called from the Struts framework.
     * @param mapping The ActionMapping used to select this instance.
     * @param form The optional ActionForm bean for this request.
     * @param request The HTTP Request we are processing.
     * @param response The HTTP Response we are processing.
     * @throws java.lang.Exception
     * @return
     */
    @Override
    public ActionForward execute(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {


             org.hibernate.SessionFactory sessionFactory=com.Auto.Common.Userinformtion.Hibernate.Userinformation_HibernateUtil.getSessionFactory();
             org.hibernate.Session Opensession=sessionFactory.openSession();
             org.hibernate.Transaction transaction=Opensession.beginTransaction();

             com.ProfileCompletion.Model.ProfileCompletion_Model ProfileCompletion=(com.ProfileCompletion.Model.ProfileCompletion_Model)form;

                String firstName=ProfileCompletion.getFirstName();
                String lastName=ProfileCompletion.getLastName();
                String id=ProfileCompletion.getId();
                String middelName=ProfileCompletion.getMiddelName();
                String address=ProfileCompletion.getAddress();
                String mobileNumber=ProfileCompletion.getMobileNumber();
                String emailId=ProfileCompletion.getEmailId();
                String gender=ProfileCompletion.getGender();
                String dob=ProfileCompletion.getDob();
                String password=ProfileCompletion.getPassword();
                String city=ProfileCompletion.getCity();
                String CountryState=ProfileCompletion.getCountryState();
                String pinCode=ProfileCompletion.getPinCode();
                String contry=ProfileCompletion.getContry();
                String profPic=ProfileCompletion.getProfPic();               
                String profileCompletion="";
                String activationCode=ProfileCompletion.getActivationCode();

                firstName=firstName.trim();

                if(firstName.equals(" ")||lastName.equals(" ")||middelName.equals(" ")||address.equals(" ")||mobileNumber.equals(" ")||emailId.equals(" ")||city.equals(" ")||CountryState.equals("")||pinCode.equals(" ")||contry.equals(" ")){
                        profileCompletion="0";
                }
                else{
                        profileCompletion="1";
                }

                System.out.println("\n\n\n\n\n"+CountryState+"\n\n\n\n\n");

                org.hibernate.Query query=Opensession.createQuery("from com.Auto.Common.Userinformtion.Hibernate.Userinformation where id="+id);


                java.util.List l=query.list();

                for (Object object : l) {

                    com.Auto.Common.Userinformtion.Hibernate.Userinformation uinfo=(com.Auto.Common.Userinformtion.Hibernate.Userinformation) object;

                    uinfo.setFirstName(firstName);
                    uinfo.setMiddelName(middelName);
                    uinfo.setLastName(lastName);
                    uinfo.setEmailId(emailId);
                    uinfo.setAddress(address);
                    uinfo.setMobileNumber(mobileNumber);
                    uinfo.setGender(gender);
                    uinfo.setPassword(password);
                    uinfo.setDob(dob);
                    uinfo.setCity(city);
                    uinfo.setContry(contry);
                    uinfo.setCountryState(CountryState);
                    uinfo.setPinCode(pinCode);
                    uinfo.setProfPic("VehicleHai/"+activationCode+"/Profile/"+activationCode+".vhi");
                    uinfo.setProfileCompletion(profileCompletion);
                    new SaveProfilePic(activationCode+"Seperate"+profPic);

                              }
                transaction.commit();

                request.setAttribute("data","profile.jsp");
                request.setAttribute("com.ProfileCompletion.Model.ProfileCompletion_Model", ProfileCompletion);
                request.setAttribute("state",profileCompletion);










        
        return mapping.findForward(SUCCESS);
    }
}
